package com.sky.controller.admin;


import com.github.pagehelper.Page;
import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.SetMealService;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.aspectj.apache.bcel.generic.LOOKUPSWITCH;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("admin/setmeal")
@Api(tags = "套餐相关接口")
@Slf4j

public class SetMealController {
    @Autowired
    private SetMealService  setMealService;

    @PostMapping
    @ApiOperation("新增套餐")
    public Result save (@RequestBody SetmealDTO setmealDTO){
        log.info("新增套餐{}",setmealDTO);
        setMealService.save(setmealDTO);

        return Result.success();
    }

    @GetMapping("page")
    @ApiOperation("套餐分页查询")
    public Result<PageResult> pageQuery(SetmealPageQueryDTO setmealPageQueryDTO){
        log.info("套餐分页查询{}",setmealPageQueryDTO);
        Page<SetmealVO> page=setMealService.pageQuery(setmealPageQueryDTO);
        PageResult pageResult = new PageResult(page.getTotal(), page.getResult());
        return Result.success(pageResult);
    }

    @PostMapping("status/{status}")
    @ApiOperation("起售停售套餐")
    public Result setStartOrCloce(@PathVariable Integer status,Integer id){
        log.info("设置套餐起售或者禁售{}",status);
        setMealService.setStartOrCloce(status,id);
        return Result.success();
    }

    @GetMapping("{id}")
    @ApiOperation("根据id查询套餐")
    public Result<SetmealVO> getById(@PathVariable Long id){
        log.info("根据id查询套餐}",id);
        SetmealVO setmealVO=setMealService.getById(id);
        return Result.success(setmealVO);
    }

    @PutMapping
    @ApiOperation("修改套餐")
    public Result update(@RequestBody SetmealDTO setmealDTO){
        log.info("修改套餐",setmealDTO);
        setMealService.update(setmealDTO);
        return Result.success();
    }

    @DeleteMapping
    @ApiOperation("批量删除询套餐")
    public Result deleteByIds(@RequestParam List<Long> ids){
        log.info("批量删除询套餐",ids);
        setMealService.deleteByIds(ids);
        return Result.success();
    }

}
